package com.ssm.util;

import com.github.pagehelper.PageInfo;
import com.ssm.pojo.Task;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 首页 上一页 1 2 3 4 5 6 下一页 末页
 */
public class PageUtil {
    public static String getPageInfo(PageInfo<Task> pageInfo, HttpServletRequest request){
        String path = request.getContextPath()+"/";
        StringBuffer builder = new StringBuffer();
        //拼接首页
        builder.append("<a href='"+path+"tasks/1'>首页</a>");

        //拼接上一页
        if(pageInfo.isHasPreviousPage()){
            builder.append("<a href='"+path+"tasks/"+pageInfo.getPrePage()+"'>上一页</a>");
        }else {
            builder.append("上一页");
        }

        //拼接页码
        int[] nums = pageInfo.getNavigatepageNums();
        for (int i : nums) {
            if(i==pageInfo.getPageNum()){
                builder.append("<a style='color:red;' href='"+path+"tasks/"+i+"'>"+i+"</a>");
            }else {
                builder.append("<a href='"+path+"tasks/"+i+"'>"+i+"</a>");
            }

        }


        //拼接下一页
        if(pageInfo.isHasNextPage()){
            builder.append("<a href='"+path+"tasks/"+pageInfo.getNextPage()+"'>下一页</a>");
        }else {
            builder.append("下一页");
        }

        //拼接首页
        builder.append("<a href='"+path+"tasks/"+pageInfo.getPages()+"'>尾页</a>");

        return builder.toString();

    }



    public static String getPageInfoAccept(PageInfo<Task> pageInfo,PageInfo<Task> pageInfo1, HttpServletRequest request){
        String path = request.getContextPath()+"/";
        StringBuffer builder = new StringBuffer();
        //拼接首页
        builder.append("<a href='"+path+"acceptSure/1'>首页</a>");

        //拼接上一页
        if(pageInfo.isHasPreviousPage()){
            builder.append("<a href='"+path+"acceptSure/"+pageInfo.getPrePage()+"'>上一页</a>");
        }else {
            builder.append("上一页");
        }

        //拼接页码
        int[] nums = pageInfo.getNavigatepageNums();
        for (int i : nums) {
            if(i==pageInfo.getPageNum()){
                builder.append("<a style='color:red;' href='"+path+"acceptSure/"+i+"'>"+i+"</a>");
            }else {
                builder.append("<a href='"+path+"acceptSure/"+i+"'>"+i+"</a>");
            }

        }


        //拼接下一页
        if(pageInfo.isHasNextPage()){
            builder.append("<a href='"+path+"acceptSure/"+pageInfo.getNextPage()+"'>下一页</a>");
        }else {
            builder.append("下一页");
        }

        //拼接首页
        builder.append("<a href='"+path+"acceptSure/"+pageInfo.getPages()+"'>尾页</a>");

        return builder.toString();

    }

    public static String getPageInfoAccept(PageInfo<Task> pageInfo, HttpServletRequest request){
        String path = request.getContextPath()+"/";
        StringBuffer builder = new StringBuffer();
        //拼接首页
        builder.append("<a href='"+path+"acceptSure/1'>首页</a>");

        //拼接上一页
        if(pageInfo.isHasPreviousPage()){
            builder.append("<a href='"+path+"acceptSure/"+pageInfo.getPrePage()+"'>上一页</a>");
        }else {
            builder.append("上一页");
        }

        //拼接页码
        int[] nums = pageInfo.getNavigatepageNums();
        for (int i : nums) {
            if(i==pageInfo.getPageNum()){
                builder.append("<a style='color:red;' href='"+path+"acceptSure/"+i+"'>"+i+"</a>");
            }else {
                builder.append("<a href='"+path+"acceptSure/"+i+"'>"+i+"</a>");
            }

        }


        //拼接下一页
        if(pageInfo.isHasNextPage()){
            builder.append("<a href='"+path+"acceptSure/"+pageInfo.getNextPage()+"'>下一页</a>");
        }else {
            builder.append("下一页");
        }

        //拼接首页
        builder.append("<a href='"+path+"acceptSure/"+pageInfo.getPages()+"'>尾页</a>");

        return builder.toString();

    }



    public static String getPageInfoSelf(PageInfo<Task> pageInfo, HttpServletRequest request){
        String path = request.getContextPath()+"/";
        StringBuffer builder = new StringBuffer();
        //拼接首页
        builder.append("<a href='"+path+"selectSelf/1'>首页</a>");

        //拼接上一页
        if(pageInfo.isHasPreviousPage()){
            builder.append("<a href='"+path+"selectSelf/"+pageInfo.getPrePage()+"'>上一页</a>");
        }else {
            builder.append("上一页");
        }

        //拼接页码
        int[] nums = pageInfo.getNavigatepageNums();
        for (int i : nums) {
            if(i==pageInfo.getPageNum()){
                builder.append("<a style='color:red;' href='"+path+"selectSelf/"+i+"'>"+i+"</a>");
            }else {
                builder.append("<a href='"+path+"selectSelf/"+i+"'>"+i+"</a>");
            }

        }


        //拼接下一页
        if(pageInfo.isHasNextPage()){
            builder.append("<a href='"+path+"selectSelf/"+pageInfo.getNextPage()+"'>下一页</a>");
        }else {
            builder.append("下一页");
        }

        //拼接首页
        builder.append("<a href='"+path+"selectSelf/"+pageInfo.getPages()+"'>尾页</a>");

        return builder.toString();

    }




    public static String getPageInfoFinish(PageInfo<Task> pageInfo, HttpServletRequest request){
        String path = request.getContextPath()+"/";
        StringBuffer builder = new StringBuffer();
        //拼接首页
        builder.append("<a href='"+path+"selectFinishTask/1'>首页</a>");

        //拼接上一页
        if(pageInfo.isHasPreviousPage()){
            builder.append("<a href='"+path+"selectFinishTask/"+pageInfo.getPrePage()+"'>上一页</a>");
        }else {
            builder.append("上一页");
        }

        //拼接页码
        int[] nums = pageInfo.getNavigatepageNums();
        for (int i : nums) {
            if(i==pageInfo.getPageNum()){
                builder.append("<a style='color:red;' href='"+path+"selectFinishTask/"+i+"'>"+i+"</a>");
            }else {
                builder.append("<a href='"+path+"selectFinishTask/"+i+"'>"+i+"</a>");
            }

        }


        //拼接下一页
        if(pageInfo.isHasNextPage()){
            builder.append("<a href='"+path+"selectFinishTask/"+pageInfo.getNextPage()+"'>下一页</a>");
        }else {
            builder.append("下一页");
        }

        //拼接首页
        builder.append("<a href='"+path+"selectFinishTask/"+pageInfo.getPages()+"'>尾页</a>");

        return builder.toString();

    }



    public static String getPageInfoCha(PageInfo<Task> pageInfo, HttpServletRequest request){
        String path = request.getContextPath()+"/";
        StringBuffer builder = new StringBuffer();
        //拼接首页
        builder.append("<a href='"+path+"chaxun/1'>首页</a>");

        //拼接上一页
        if(pageInfo.isHasPreviousPage()){
            builder.append("<a href='"+path+"chaxun/"+pageInfo.getPrePage()+"'>上一页</a>");
        }else {
            builder.append("上一页");
        }

        //拼接页码
        int[] nums = pageInfo.getNavigatepageNums();
        for (int i : nums) {
            if(i==pageInfo.getPageNum()){
                builder.append("<a style='color:red;' href='"+path+"chaxun/"+i+"'>"+i+"</a>");
            }else {
                builder.append("<a href='"+path+"chaxun/"+i+"'>"+i+"</a>");
            }
        }

        //拼接下一页
        if(pageInfo.isHasNextPage()){
            builder.append("<a href='"+path+"chaxun/"+pageInfo.getNextPage()+"'>下一页</a>");
        }else {
            builder.append("下一页");
        }

        //拼接首页
        builder.append("<a href='"+path+"chaxun/"+pageInfo.getPages()+"'>尾页</a>");

        return builder.toString();
    }
}
